﻿using System;
using System.Web.UI;
using Telerik.Web.UI;

public partial class Demos_Tree_ListBox : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindProperties();
        if (!IsPostBack)
        {
            BindTreeView();
            LoadForListBox();
        }
    }

    void BindTreeView()
    {
        RadTreeView treeview = RadComboBoxTreeList.Items[0].FindControl("RadTreeView1") as RadTreeView;
        new RadTreeViewBinder(true).LoadAllNodes(treeview);
        treeview.Nodes.Insert(0, new RadTreeNode("顶级", "0"));
    }

    void BindProperties()
    {
        RadListBoxCommandBinder b1 = new RadListBoxCommandBinder(RadListBoxSource, RadListBoxDest);
        b1.ActionComplete += Button1_Click;
    }

    void LoadForListBox()
    {
        const string sql = "select * from [lt_Menu] where m_parentid={0} and m_disabled={1} order by m_sortindex asc";
        string parentId = RadComboBoxTreeList.SelectedValue;
        if (string.IsNullOrEmpty(parentId))
            parentId = "0";
        RadListBoxSource.DataSource = SqlHelper.Instance.ExecuteReader(string.Format(sql, parentId, "0"));
        RadListBoxSource.DataBind();
        RadListBoxSource.SortItems();
        RadListBoxDest.DataSource = SqlHelper.Instance.ExecuteReader(string.Format(sql, parentId, "1"));
        RadListBoxDest.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        LoadForListBox();
        BindTreeView();
    }
}